﻿using System.Web.Mvc;
using DDDSample.Domain.Location;

namespace DDDSample.UI.Mvc.Controllers
{
    public class DatabaseController : Controller
    {
        public ActionResult Reset()
        {
            var sessionFactory = IocHelper.BuildSessionFactory(true);
            using (var session = sessionFactory.OpenSession())
            {
                session.Save(new Location(new UnLocode("CNHKG"), "Hongkong"));
                session.Save(new Location(new UnLocode("AUMEL"), "Melbourne"));
                session.Save(new Location(new UnLocode("SESTO"), "Stockholm"));
                session.Save(new Location(new UnLocode("FIHEL"), "Helsinki"));
                session.Save(new Location(new UnLocode("USCHI"), "Chicago"));
                session.Save(new Location(new UnLocode("JNTKO"), "Tokyo"));
                session.Save(new Location(new UnLocode("DEHAM"), "Hamburg"));
                session.Save(new Location(new UnLocode("CNSHA"), "Shanghai"));
                session.Save(new Location(new UnLocode("NLRTM"), "Rotterdam"));
                session.Save(new Location(new UnLocode("SEGOT"), "Göteborg"));
                session.Save(new Location(new UnLocode("CNHGH"), "Hangzhou"));
                session.Save(new Location(new UnLocode("USNYC"), "New York"));
                session.Save(new Location(new UnLocode("USDAL"), "Dallas"));
                session.Flush();
            }
            return RedirectToAction("Index", "Home");         
        }
    }
}